
//  Document   : validate
//  Created on : June 1, 2012, 6:42:10 AM
//  Author     : Congpt
jQuery.noConflict();
function setFadeOutErrorValidate(active,IDdv,infor){
    if(active){
        var loca = jQuery("#"+IDdv).offset();
        var top = parseInt(loca.top) - 164;
        var left = parseInt(loca.left) - 130;
        jQuery("#ContainerErrorResult").css("left", left);
        jQuery("#ContainerErrorResult").css("top", top);
        jQuery("#resultPopUp").text(infor);
        jQuery("#popupResult").slideDown("slow", function() {
            jQuery("#popupResult").slideUp(5000);
        });
    }else{
        jQuery("#popupResult").slideUp();
    }
}

function checkvalidateListingForm(){
    //validate driver name:not null!
    var Cname = jQuery("#txtCompanyName").val();
    if(Cname == null || Cname.length == 0){
        setFadeOutErrorValidate(true,'txtCompanyName','Company Name is invalid');
        return false;
    }
    //validate password:not null!
    var pass = jQuery("#txtCompanyPass").val();
    if(pass == null || pass.length == 0){
        setFadeOutErrorValidate(true, 'txtCompanyPass', 'Password is required');
        return false;
    }

    //validate contact person:not null,Allows only letters, numbers and spaces. All other characters will return an error.
    var characterReg = /^\s*[a-zA-Z0-9,\s]+\s*$/;
    var contactPerson = jQuery("#txtContact").val();
    if(contactPerson == null || contactPerson.length == 0){
        setFadeOutErrorValidate(true, 'txtContact', 'Contact Person is required');
        return false;
    }
    if(!characterReg.test(contactPerson)){
        setFadeOutErrorValidate(true, 'txtContact', 'Contact Person allows only letters, numbers and spaces');
        return false;
    }

    //validate Designation:not null
    var design = jQuery("#txtComDesign").val();
    if(design == null || design.length == 0){
        setFadeOutErrorValidate(true, 'txtComDesign', 'Designation is required');
        return false;
    }

    //validate Address:not null
    var add = jQuery("#txtComAdd").val();
    if(add == null || add.length == 0){
        setFadeOutErrorValidate(true, 'txtComAdd', 'Address is required');
        return false;
    }

    //validate City:not null
    var city = jQuery("#txtComCity").val();
    if(city == null || city.length == 0){
        setFadeOutErrorValidate(true, 'txtComCity', 'City is required');
        return false;
    }

    //validate mobile phone:not null,allow number only
    var mPhone = jQuery("#txtComMobile").val();
    var re =/^[0][1-9][0-9]{8,9}$/;
    if(mPhone == null || mPhone.length == 0){
        setFadeOutErrorValidate(true, 'txtComMobile', 'Mobile phone is required');
        return false;
    }
    if(!re.test(mPhone)){
        setFadeOutErrorValidate(true, 'txtComMobile', 'Mobile phone is invalid');
        return false;
    }

    //validate Telephone:not null,allow number only
    var numericReg = /^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$/;
    var telephone = jQuery("#txtComTele").val();
    if(telephone == null || telephone.length == 0){
        setFadeOutErrorValidate(true, 'txtComTele', 'Telephone is required');
        return false;
    }
    if(!numericReg.test(telephone)){
        setFadeOutErrorValidate(true, 'txtComTele', 'Telephone is invalid');
        return false;
    }

    //validate Fax Number:
    var numericReg = /^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$/;
    var Fax = jQuery("#txtComFax").val();
    if(Fax == null || Fax.length == 0){
        setFadeOutErrorValidate(true, 'txtComFax', 'Fax Number is required');
        return false;
    }
    if(!numericReg.test(Fax)){
        setFadeOutErrorValidate(true, 'txtComFax', 'Fax Number is invalid');
        return false;
    }

    //validate Email:not null,format email
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    var email = jQuery("#txtComEmail").val();
    if(email == null || email.length == 0){
        setFadeOutErrorValidate(true, 'txtComEmail', 'Email is required');
        return false;
    }
    if(!emailReg.test(email)){
        setFadeOutErrorValidate(true, 'txtComEmail', 'Email is invalid');
        return false;
    }

    //validate Member type: choose option
    var membertype = jQuery("#member-type").val();
    if(membertype == 0){
        setFadeOutErrorValidate(true, 'member-type', 'Please choose Member type');
        return false;
    }

    //validate Payment Type Listing: choose option
    var paytypeListing = jQuery("#payment-type-listing").val();
    if(paytypeListing == 0){
        setFadeOutErrorValidate(true, 'payment-type-listing', 'Please choose payment type');
        return false;
    }
    return true;

}
function checkvalidateDriverForm(){
    //validate company name:not null!
    var Dname = jQuery("#txtDName").val();
    if(Dname == null || Dname.length == 0){
        setFadeOutErrorValidate(true,'txtDName','Driver Name is required');
        return false;
    }
    //validate password:not null!
    var pass = jQuery("#txtDPass").val();
    if(pass == null || pass.length == 0){
        setFadeOutErrorValidate(true, 'txtDPass', 'Password is required');
        return false;
    }

    //validate contact person:not null,Allows only letters, numbers and spaces. All other characters will return an error.
    var characterReg = /^\s*[a-zA-Z0-9,\s]+\s*$/;
    var contactPerson = jQuery("#txtDContact").val();
    if(contactPerson == null || contactPerson.length == 0){
        setFadeOutErrorValidate(true, 'txtDContact', 'Contact Person is required');
        return false;
    }
    if(!characterReg.test(contactPerson)){
        setFadeOutErrorValidate(true, 'txtDContact', 'Contact Person allows only letters, numbers and spaces');
        return false;
    }

    //validate Address:not null
    var add = jQuery("#txtDAdd").val();
    if(add == null || add.length == 0){
        setFadeOutErrorValidate(true, 'txtDAdd', 'Address is required');
        return false;
    }

    //validate Address:not null
    var city = jQuery("#txtDCity").val();
    if(city == null || city.length == 0){
        setFadeOutErrorValidate(true, 'txtDCity', 'City is required');
        return false;
    }

    //validate mobile phone:not null,allow number only
    var mPhone = jQuery("#txtDMobile").val();
    var re =/^[0][1-9][0-9]{8,9}$/;
    if(mPhone == null || mPhone.length == 0){
        setFadeOutErrorValidate(true, 'txtDMobile', 'Mobile phone is required');
        return false;
    }
    if(!re.test(mPhone)){
        setFadeOutErrorValidate(true, 'txtDMobile', 'Mobile phone is invalid');
        return false;
    }

    //validate Telephone:not null,allow number only
    var numericReg = /^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$/;
    var telephone = jQuery("#txtDTele").val();
    if(telephone == null || telephone.length == 0){
        setFadeOutErrorValidate(true, 'txtDTele', 'Telephone is required');
        return false;
    }
    if(!numericReg.test(mPhone)){
        setFadeOutErrorValidate(true, 'txtDTele', 'Telephone is invalid');
        return false;
    }



    //validate Email:not null,format email
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    var email = jQuery("#txtDEmail").val();
    if(email == null || email.length == 0){
        setFadeOutErrorValidate(true, 'txtDEmail', 'Email is required');
        return false;
    }
    if(!emailReg.test(email)){
        setFadeOutErrorValidate(true, 'txtDEmail', 'Email is invalid');
        return false;
    }

    //validate Experience:not null
    var experi = jQuery("#txtDExperience").val();
    if(experi == null || experi.length == 0){
        setFadeOutErrorValidate(true, 'txtDExperience', 'Experience is required');
        return false;
    }

    //validate Description:
    var description = jQuery("#txtDDescription").val();
    if(description == null || description.length == 0){
        setFadeOutErrorValidate(true, 'txtDDescription', 'Description is required');
        return false;
    }
    //validate Payment Type Driver: choose option
    var paytypeDriver = jQuery("#payment-type-driver").val();
    if(paytypeDriver == 0){
        setFadeOutErrorValidate(true, 'payment-type-driver', 'Please choose payment type');
        return false;
    }

    return true;

}
function checkvalidateADVForm(){
    //validate driver name:not null!
    var Cname = jQuery("#txtAdverName").val();
    if(Cname == null || Cname.length == 0){
        setFadeOutErrorValidate(true,'txtAdverName','Company Name is required');
        return false;
    }

    //validate Designation:not null
    var design = jQuery("#txtAdverDesign").val();
    if(design == null || design.length == 0){
        setFadeOutErrorValidate(true, 'txtAdverDesign', 'Designation is required');
        return false;
    }

    //validate Address:not null
    var add = jQuery("#txtAdverAdd").val();
    if(add == null || add.length == 0){
        setFadeOutErrorValidate(true, 'txtAdverAdd', 'Address is required');
        return false;
    }
    //validate mobile phone:not null,allow number only
    var mPhone = jQuery("#txtAdverMobile").val();
    var re =/^[0][1-9][0-9]{8,9}$/;
    if(mPhone == null || mPhone.length == 0){
        setFadeOutErrorValidate(true, 'txtAdverMobile', 'Mobile phone is required');
        return false;
    }
    if(!re.test(mPhone)){
        setFadeOutErrorValidate(true, 'txtAdverMobile', 'Mobile phone is invalid');
        return false;
    }

    //validate Telephone:not null,allow number only
    var numericReg = /^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$/;
    var telephone = jQuery("#txtAdverTele").val();
    if(telephone == null || telephone.length == 0){
        setFadeOutErrorValidate(true, 'txtAdverTele', 'Telephone is required');
        return false;
    }
    if(!numericReg.test(mPhone)){
        setFadeOutErrorValidate(true, 'txtAdverTele', 'Telephone is invalid');
        return false;
    }

    //validate Fax Number:
    var numericReg = /^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$/;
    var Fax = jQuery("#txtAdverFax").val();
    if(Fax == null || Fax.length == 0){
        setFadeOutErrorValidate(true, 'txtAdverFax', 'Fax Number is required');
        return false;
    }
    if(!numericReg.test(Fax)){
        setFadeOutErrorValidate(true, 'txtAdverFax', 'Fax Number is invalid');
        return false;
    }

    //validate Email:not null,format email
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    var email = jQuery("#txtAdverEmail").val();
    if(email == null || email.length == 0){
        setFadeOutErrorValidate(true, 'txtAdverEmail', 'Email is required');
        return false;
    }
    if(!emailReg.test(email)){
        setFadeOutErrorValidate(true, 'txtAdverEmail', 'Email is invalid');
        return false;
    }

    //validate Description:
    var description = jQuery("#txtAdverDescription").val();
    if(description == null || description.length == 0){
        setFadeOutErrorValidate(true, 'txtAdverDescription', 'Description is required');
        return false;
    }

    //validate Payment Type Advertise: choose option
    var paytypeAdvertise = jQuery("#payment-type-advertise").val();
    if(paytypeAdvertise == 0){
        setFadeOutErrorValidate(true, 'payment-type-advertise', 'Please choose payment type');
        return false;
    }

    return true;
}

function checkvalidateFeedbackForm(){
    //validate name:not null!
    var Cname = jQuery("#txtFName").val();
    if(Cname == null || Cname.length == 0){
        setFadeOutErrorValidate(true,'txtFName','Company Name is required');
        return false;
    }

    //validate Email:not null,format email
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    var email = jQuery("#txtFEmail").val();
    if(email == null || email.length == 0){
        setFadeOutErrorValidate(true, 'txtFEmail', 'Email is required');
        return false;
    }
    if(!emailReg.test(email)){
        setFadeOutErrorValidate(true, 'txtFEmail', 'Email is invalid');
        return false;
    }

    //validate Description:
    var description = jQuery("#txtFDes").val();
    if(description == null || description.length == 0){
        setFadeOutErrorValidate(true, 'txtFDes', 'Description is required');
        return false;
    }

    //validate City:not null
    var city = jQuery("#txtFCity").val();
    if(city == null || city.length == 0){
        setFadeOutErrorValidate(true, 'txtFCity', 'City is required');
        return false;
    }

    //validate Feedback Type : choose option
    var paytypeAdvertise = jQuery("#type-feedback").val();
    if(paytypeAdvertise == 'Choose'){
        setFadeOutErrorValidate(true, 'type-feedback', 'Please choose payment type');
        return false;
    }
    return true;
}

function checkValidateLogin(IDdv){
    if(IDdv == 'Advertise'){
        var username = jQuery("#txtUser").val();
        if(username == null || username.length == 0){
            setFadeOutErrorValidate(true, 'txtUser', 'username is required');
            return false;
        }
    }else{
        var username = jQuery("#txtUser").val();
        var pass = jQuery("#txtPass").val();

        if(username == null || username.length == 0){
            setFadeOutErrorValidate(true, 'txtUser', 'username is required');

            return false;
        }

        if(pass == null || pass.length == 0){
            setFadeOutErrorValidate(true, 'txtPass', 'PassWord is required');

            return false;
        }
    }
    return true;
}